{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.1 Data in the 21st Century"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.2 Introducing pandas"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.2.1 Pandas vs. Graphical Spreadsheet Applications"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.2.2 Pandas vs. Its Competitors"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.3 A Tour of Pandas"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.3.1 Importing a Data Set"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Rank</th>\n",
       "      <th>Title</th>\n",
       "      <th>Studio</th>\n",
       "      <th>Gross</th>\n",
       "      <th>Year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>Avengers: Endgame</td>\n",
       "      <td>Buena Vista</td>\n",
       "      <td>$2,796.30</td>\n",
       "      <td>2019</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>Avatar</td>\n",
       "      <td>Fox</td>\n",
       "      <td>$2,789.70</td>\n",
       "      <td>2009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>Titanic</td>\n",
       "      <td>Paramount</td>\n",
       "      <td>$2,187.50</td>\n",
       "      <td>1997</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>Star Wars: The Force Awakens</td>\n",
       "      <td>Buena Vista</td>\n",
       "      <td>$2,068.20</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>Avengers: Infinity War</td>\n",
       "      <td>Buena Vista</td>\n",
       "      <td>$2,048.40</td>\n",
       "      <td>2018</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>777</th>\n",
       "      <td>778</td>\n",
       "      <td>Yogi Bear</td>\n",
       "      <td>Warner Brothers</td>\n",
       "      <td>$201.60</td>\n",
       "      <td>2010</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>778</th>\n",
       "      <td>779</td>\n",
       "      <td>Garfield: The Movie</td>\n",
       "      <td>Fox</td>\n",
       "      <td>$200.80</td>\n",
       "      <td>2004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>779</th>\n",
       "      <td>780</td>\n",
       "      <td>Cats &amp; Dogs</td>\n",
       "      <td>Warner Brothers</td>\n",
       "      <td>$200.70</td>\n",
       "      <td>2001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>780</th>\n",
       "      <td>781</td>\n",
       "      <td>The Hunt for Red October</td>\n",
       "      <td>Paramount</td>\n",
       "      <td>$200.50</td>\n",
       "      <td>1990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>781</th>\n",
       "      <td>782</td>\n",
       "      <td>Valkyrie</td>\n",
       "      <td>MGM</td>\n",
       "      <td>$200.30</td>\n",
       "      <td>2008</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>782 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     Rank                         Title           Studio       Gross  Year\n",
       "0       1             Avengers: Endgame      Buena Vista  $2,796.30   2019\n",
       "1       2                        Avatar              Fox  $2,789.70   2009\n",
       "2       3                       Titanic        Paramount  $2,187.50   1997\n",
       "3       4  Star Wars: The Force Awakens      Buena Vista  $2,068.20   2015\n",
       "4       5        Avengers: Infinity War      Buena Vista  $2,048.40   2018\n",
       "..    ...                           ...              ...         ...   ...\n",
       "777   778                     Yogi Bear  Warner Brothers    $201.60   2010\n",
       "778   779           Garfield: The Movie              Fox    $200.80   2004\n",
       "779   780                   Cats & Dogs  Warner Brothers    $200.70   2001\n",
       "780   781      The Hunt for Red October        Paramount    $200.50   1990\n",
       "781   782                      Valkyrie              MGM    $200.30   2008\n",
       "\n",
       "[782 rows x 5 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_csv(\"movies.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Rank</th>\n",
       "      <th>Studio</th>\n",
       "      <th>Gross</th>\n",
       "      <th>Year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Title</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Avengers: Endgame</th>\n",
       "      <td>1</td>\n",
       "      <td>Buena Vista</td>\n",
       "      <td>$2,796.30</td>\n",
       "      <td>2019</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Avatar</th>\n",
       "      <td>2</td>\n",
       "      <td>Fox</td>\n",
       "      <td>$2,789.70</td>\n",
       "      <td>2009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Titanic</th>\n",
       "      <td>3</td>\n",
       "      <td>Paramount</td>\n",
       "      <td>$2,187.50</td>\n",
       "      <td>1997</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Star Wars: The Force Awakens</th>\n",
       "      <td>4</td>\n",
       "      <td>Buena Vista</td>\n",
       "      <td>$2,068.20</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Avengers: Infinity War</th>\n",
       "      <td>5</td>\n",
       "      <td>Buena Vista</td>\n",
       "      <td>$2,048.40</td>\n",
       "      <td>2018</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Yogi Bear</th>\n",
       "      <td>778</td>\n",
       "      <td>Warner Brothers</td>\n",
       "      <td>$201.60</td>\n",
       "      <td>2010</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Garfield: The Movie</th>\n",
       "      <td>779</td>\n",
       "      <td>Fox</td>\n",
       "      <td>$200.80</td>\n",
       "      <td>2004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Cats &amp; Dogs</th>\n",
       "      <td>780</td>\n",
       "      <td>Warner Brothers</td>\n",
       "      <td>$200.70</td>\n",
       "      <td>2001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Hunt for Red October</th>\n",
       "      <td>781</td>\n",
       "      <td>Paramount</td>\n",
       "      <td>$200.50</td>\n",
       "      <td>1990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Valkyrie</th>\n",
       "      <td>782</td>\n",
       "      <td>MGM</td>\n",
       "      <td>$200.30</td>\n",
       "      <td>2008</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>782 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                              Rank           Studio       Gross  Year\n",
       "Title                                                                \n",
       "Avengers: Endgame                1      Buena Vista  $2,796.30   2019\n",
       "Avatar                           2              Fox  $2,789.70   2009\n",
       "Titanic                          3        Paramount  $2,187.50   1997\n",
       "Star Wars: The Force Awakens     4      Buena Vista  $2,068.20   2015\n",
       "Avengers: Infinity War           5      Buena Vista  $2,048.40   2018\n",
       "...                            ...              ...         ...   ...\n",
       "Yogi Bear                      778  Warner Brothers    $201.60   2010\n",
       "Garfield: The Movie            779              Fox    $200.80   2004\n",
       "Cats & Dogs                    780  Warner Brothers    $200.70   2001\n",
       "The Hunt for Red October       781        Paramount    $200.50   1990\n",
       "Valkyrie                       782              MGM    $200.30   2008\n",
       "\n",
       "[782 rows x 4 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_csv(\"movies.csv\", index_col = \"Title\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "movies = pd.read_csv(\"movies.csv\", index_col = \"Title\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.3.2 Manipulating a DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Rank</th>\n",
       "      <th>Studio</th>\n",
       "      <th>Gross</th>\n",
       "      <th>Year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Title</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Avengers: Endgame</th>\n",
       "      <td>1</td>\n",
       "      <td>Buena Vista</td>\n",
       "      <td>$2,796.30</td>\n",
       "      <td>2019</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Avatar</th>\n",
       "      <td>2</td>\n",
       "      <td>Fox</td>\n",
       "      <td>$2,789.70</td>\n",
       "      <td>2009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Titanic</th>\n",
       "      <td>3</td>\n",
       "      <td>Paramount</td>\n",
       "      <td>$2,187.50</td>\n",
       "      <td>1997</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Star Wars: The Force Awakens</th>\n",
       "      <td>4</td>\n",
       "      <td>Buena Vista</td>\n",
       "      <td>$2,068.20</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                              Rank       Studio       Gross  Year\n",
       "Title                                                            \n",
       "Avengers: Endgame                1  Buena Vista  $2,796.30   2019\n",
       "Avatar                           2          Fox  $2,789.70   2009\n",
       "Titanic                          3    Paramount  $2,187.50   1997\n",
       "Star Wars: The Force Awakens     4  Buena Vista  $2,068.20   2015"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies.head(4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Rank</th>\n",
       "      <th>Studio</th>\n",
       "      <th>Gross</th>\n",
       "      <th>Year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Title</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>21 Jump Street</th>\n",
       "      <td>777</td>\n",
       "      <td>Sony</td>\n",
       "      <td>$201.60</td>\n",
       "      <td>2012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Yogi Bear</th>\n",
       "      <td>778</td>\n",
       "      <td>Warner Brothers</td>\n",
       "      <td>$201.60</td>\n",
       "      <td>2010</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Garfield: The Movie</th>\n",
       "      <td>779</td>\n",
       "      <td>Fox</td>\n",
       "      <td>$200.80</td>\n",
       "      <td>2004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Cats &amp; Dogs</th>\n",
       "      <td>780</td>\n",
       "      <td>Warner Brothers</td>\n",
       "      <td>$200.70</td>\n",
       "      <td>2001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Hunt for Red October</th>\n",
       "      <td>781</td>\n",
       "      <td>Paramount</td>\n",
       "      <td>$200.50</td>\n",
       "      <td>1990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Valkyrie</th>\n",
       "      <td>782</td>\n",
       "      <td>MGM</td>\n",
       "      <td>$200.30</td>\n",
       "      <td>2008</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                          Rank           Studio     Gross  Year\n",
       "Title                                                          \n",
       "21 Jump Street             777             Sony  $201.60   2012\n",
       "Yogi Bear                  778  Warner Brothers  $201.60   2010\n",
       "Garfield: The Movie        779              Fox  $200.80   2004\n",
       "Cats & Dogs                780  Warner Brothers  $200.70   2001\n",
       "The Hunt for Red October   781        Paramount  $200.50   1990\n",
       "Valkyrie                   782              MGM  $200.30   2008"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies.tail(6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "782"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(movies)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(782, 4)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3128"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies.size"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Rank       int64\n",
       "Studio    object\n",
       "Gross     object\n",
       "Year       int64\n",
       "dtype: object"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Rank           500\n",
       "Studio         Fox\n",
       "Gross     $288.30 \n",
       "Year          2018\n",
       "Name: Maze Runner: The Death Cure, dtype: object"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies.iloc[499]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Rank            119\n",
       "Studio    Paramount\n",
       "Gross      $677.90 \n",
       "Year           1994\n",
       "Name: Forrest Gump, dtype: object"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies.loc[\"Forrest Gump\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Rank</th>\n",
       "      <th>Studio</th>\n",
       "      <th>Gross</th>\n",
       "      <th>Year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Title</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>101 Dalmatians</th>\n",
       "      <td>425</td>\n",
       "      <td>Buena Vista</td>\n",
       "      <td>$320.70</td>\n",
       "      <td>1996</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101 Dalmatians</th>\n",
       "      <td>708</td>\n",
       "      <td>Buena Vista</td>\n",
       "      <td>$215.90</td>\n",
       "      <td>1961</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                Rank       Studio     Gross  Year\n",
       "Title                                            \n",
       "101 Dalmatians   425  Buena Vista  $320.70   1996\n",
       "101 Dalmatians   708  Buena Vista  $215.90   1961"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies.loc[\"101 Dalmatians\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Rank</th>\n",
       "      <th>Studio</th>\n",
       "      <th>Gross</th>\n",
       "      <th>Year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Title</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Avengers: Endgame</th>\n",
       "      <td>1</td>\n",
       "      <td>Buena Vista</td>\n",
       "      <td>$2,796.30</td>\n",
       "      <td>2019</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>John Wick: Chapter 3 - Parabellum</th>\n",
       "      <td>458</td>\n",
       "      <td>Lionsgate</td>\n",
       "      <td>$304.70</td>\n",
       "      <td>2019</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Wandering Earth</th>\n",
       "      <td>114</td>\n",
       "      <td>China Film Corporation</td>\n",
       "      <td>$699.80</td>\n",
       "      <td>2019</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Toy Story 4</th>\n",
       "      <td>198</td>\n",
       "      <td>Buena Vista</td>\n",
       "      <td>$519.80</td>\n",
       "      <td>2019</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>How to Train Your Dragon: The Hidden World</th>\n",
       "      <td>199</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$519.80</td>\n",
       "      <td>2019</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            Rank                  Studio  \\\n",
       "Title                                                                      \n",
       "Avengers: Endgame                              1             Buena Vista   \n",
       "John Wick: Chapter 3 - Parabellum            458               Lionsgate   \n",
       "The Wandering Earth                          114  China Film Corporation   \n",
       "Toy Story 4                                  198             Buena Vista   \n",
       "How to Train Your Dragon: The Hidden World   199               Universal   \n",
       "\n",
       "                                                 Gross  Year  \n",
       "Title                                                         \n",
       "Avengers: Endgame                           $2,796.30   2019  \n",
       "John Wick: Chapter 3 - Parabellum             $304.70   2019  \n",
       "The Wandering Earth                           $699.80   2019  \n",
       "Toy Story 4                                   $519.80   2019  \n",
       "How to Train Your Dragon: The Hidden World    $519.80   2019  "
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies.sort_values(by = \"Year\", ascending = False).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Rank</th>\n",
       "      <th>Studio</th>\n",
       "      <th>Gross</th>\n",
       "      <th>Year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Title</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>The Blair Witch Project</th>\n",
       "      <td>588</td>\n",
       "      <td>Artisan</td>\n",
       "      <td>$248.60</td>\n",
       "      <td>1999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101 Dalmatians</th>\n",
       "      <td>708</td>\n",
       "      <td>Buena Vista</td>\n",
       "      <td>$215.90</td>\n",
       "      <td>1961</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Jungle Book</th>\n",
       "      <td>755</td>\n",
       "      <td>Buena Vista</td>\n",
       "      <td>$205.80</td>\n",
       "      <td>1967</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Who Framed Roger Rabbit</th>\n",
       "      <td>410</td>\n",
       "      <td>Buena Vista</td>\n",
       "      <td>$329.80</td>\n",
       "      <td>1988</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dead Poets Society</th>\n",
       "      <td>636</td>\n",
       "      <td>Buena Vista</td>\n",
       "      <td>$235.90</td>\n",
       "      <td>1989</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                         Rank       Studio     Gross  Year\n",
       "Title                                                     \n",
       "The Blair Witch Project   588      Artisan  $248.60   1999\n",
       "101 Dalmatians            708  Buena Vista  $215.90   1961\n",
       "The Jungle Book           755  Buena Vista  $205.80   1967\n",
       "Who Framed Roger Rabbit   410  Buena Vista  $329.80   1988\n",
       "Dead Poets Society        636  Buena Vista  $235.90   1989"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies.sort_values(by = [\"Studio\", \"Year\"]).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Rank</th>\n",
       "      <th>Studio</th>\n",
       "      <th>Gross</th>\n",
       "      <th>Year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Title</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>10,000 B.C.</th>\n",
       "      <td>536</td>\n",
       "      <td>Warner Brothers</td>\n",
       "      <td>$269.80</td>\n",
       "      <td>2008</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101 Dalmatians</th>\n",
       "      <td>708</td>\n",
       "      <td>Buena Vista</td>\n",
       "      <td>$215.90</td>\n",
       "      <td>1961</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101 Dalmatians</th>\n",
       "      <td>425</td>\n",
       "      <td>Buena Vista</td>\n",
       "      <td>$320.70</td>\n",
       "      <td>1996</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2 Fast 2 Furious</th>\n",
       "      <td>632</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$236.40</td>\n",
       "      <td>2003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012</th>\n",
       "      <td>93</td>\n",
       "      <td>Sony</td>\n",
       "      <td>$769.70</td>\n",
       "      <td>2009</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  Rank           Studio     Gross  Year\n",
       "Title                                                  \n",
       "10,000 B.C.        536  Warner Brothers  $269.80   2008\n",
       "101 Dalmatians     708      Buena Vista  $215.90   1961\n",
       "101 Dalmatians     425      Buena Vista  $320.70   1996\n",
       "2 Fast 2 Furious   632        Universal  $236.40   2003\n",
       "2012                93             Sony  $769.70   2009"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies.sort_index().head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.3.3 Counting Values in a Series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Title\n",
       "Avengers: Endgame                   Buena Vista\n",
       "Avatar                                      Fox\n",
       "Titanic                               Paramount\n",
       "Star Wars: The Force Awakens        Buena Vista\n",
       "Avengers: Infinity War              Buena Vista\n",
       "                                     ...       \n",
       "Yogi Bear                       Warner Brothers\n",
       "Garfield: The Movie                         Fox\n",
       "Cats & Dogs                     Warner Brothers\n",
       "The Hunt for Red October              Paramount\n",
       "Valkyrie                                    MGM\n",
       "Name: Studio, Length: 782, dtype: object"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies[\"Studio\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Warner Brothers    132\n",
       "Buena Vista        125\n",
       "Fox                117\n",
       "Universal          109\n",
       "Sony                86\n",
       "Paramount           76\n",
       "Dreamworks          27\n",
       "Lionsgate           21\n",
       "New Line            16\n",
       "TriStar             11\n",
       "Name: Studio, dtype: int64"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies[\"Studio\"].value_counts().head(10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.3.4\tFiltering a Column by One or More Criteria"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Rank</th>\n",
       "      <th>Studio</th>\n",
       "      <th>Gross</th>\n",
       "      <th>Year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Title</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Jurassic World</th>\n",
       "      <td>6</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$1,671.70</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Furious 7</th>\n",
       "      <td>8</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$1,516.00</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jurassic World: Fallen Kingdom</th>\n",
       "      <td>13</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$1,309.50</td>\n",
       "      <td>2018</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Fate of the Furious</th>\n",
       "      <td>17</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$1,236.00</td>\n",
       "      <td>2017</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Minions</th>\n",
       "      <td>19</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$1,159.40</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Break-Up</th>\n",
       "      <td>763</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$205.00</td>\n",
       "      <td>2006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Everest</th>\n",
       "      <td>766</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$203.40</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Patch Adams</th>\n",
       "      <td>772</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$202.30</td>\n",
       "      <td>1998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kindergarten Cop</th>\n",
       "      <td>775</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$202.00</td>\n",
       "      <td>1990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Straight Outta Compton</th>\n",
       "      <td>776</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$201.60</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>109 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                Rank     Studio       Gross  Year\n",
       "Title                                                            \n",
       "Jurassic World                     6  Universal  $1,671.70   2015\n",
       "Furious 7                          8  Universal  $1,516.00   2015\n",
       "Jurassic World: Fallen Kingdom    13  Universal  $1,309.50   2018\n",
       "The Fate of the Furious           17  Universal  $1,236.00   2017\n",
       "Minions                           19  Universal  $1,159.40   2015\n",
       "...                              ...        ...         ...   ...\n",
       "The Break-Up                     763  Universal    $205.00   2006\n",
       "Everest                          766  Universal    $203.40   2015\n",
       "Patch Adams                      772  Universal    $202.30   1998\n",
       "Kindergarten Cop                 775  Universal    $202.00   1990\n",
       "Straight Outta Compton           776  Universal    $201.60   2015\n",
       "\n",
       "[109 rows x 4 columns]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies[movies[\"Studio\"] == \"Universal\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Rank</th>\n",
       "      <th>Studio</th>\n",
       "      <th>Gross</th>\n",
       "      <th>Year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Title</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Jurassic World</th>\n",
       "      <td>6</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$1,671.70</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Furious 7</th>\n",
       "      <td>8</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$1,516.00</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jurassic World: Fallen Kingdom</th>\n",
       "      <td>13</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$1,309.50</td>\n",
       "      <td>2018</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Fate of the Furious</th>\n",
       "      <td>17</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$1,236.00</td>\n",
       "      <td>2017</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Minions</th>\n",
       "      <td>19</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$1,159.40</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                Rank     Studio       Gross  Year\n",
       "Title                                                            \n",
       "Jurassic World                     6  Universal  $1,671.70   2015\n",
       "Furious 7                          8  Universal  $1,516.00   2015\n",
       "Jurassic World: Fallen Kingdom    13  Universal  $1,309.50   2018\n",
       "The Fate of the Furious           17  Universal  $1,236.00   2017\n",
       "Minions                           19  Universal  $1,159.40   2015"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "released_by_universal = (movies[\"Studio\"] == \"Universal\")\n",
    "movies[released_by_universal].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Rank</th>\n",
       "      <th>Studio</th>\n",
       "      <th>Gross</th>\n",
       "      <th>Year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Title</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Jurassic World</th>\n",
       "      <td>6</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$1,671.70</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Furious 7</th>\n",
       "      <td>8</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$1,516.00</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Minions</th>\n",
       "      <td>19</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$1,159.40</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Fifty Shades of Grey</th>\n",
       "      <td>165</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$571.00</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Pitch Perfect 2</th>\n",
       "      <td>504</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$287.50</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ted 2</th>\n",
       "      <td>702</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$216.70</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Everest</th>\n",
       "      <td>766</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$203.40</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Straight Outta Compton</th>\n",
       "      <td>776</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$201.60</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        Rank     Studio       Gross  Year\n",
       "Title                                                    \n",
       "Jurassic World             6  Universal  $1,671.70   2015\n",
       "Furious 7                  8  Universal  $1,516.00   2015\n",
       "Minions                   19  Universal  $1,159.40   2015\n",
       "Fifty Shades of Grey     165  Universal    $571.00   2015\n",
       "Pitch Perfect 2          504  Universal    $287.50   2015\n",
       "Ted 2                    702  Universal    $216.70   2015\n",
       "Everest                  766  Universal    $203.40   2015\n",
       "Straight Outta Compton   776  Universal    $201.60   2015"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "released_by_universal = movies[\"Studio\"] == \"Universal\"\n",
    "released_in_2015 = movies[\"Year\"] == 2015\n",
    "movies[released_by_universal & released_in_2015]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Rank</th>\n",
       "      <th>Studio</th>\n",
       "      <th>Gross</th>\n",
       "      <th>Year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Title</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Star Wars: The Force Awakens</th>\n",
       "      <td>4</td>\n",
       "      <td>Buena Vista</td>\n",
       "      <td>$2,068.20</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jurassic World</th>\n",
       "      <td>6</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$1,671.70</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Furious 7</th>\n",
       "      <td>8</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$1,516.00</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Avengers: Age of Ultron</th>\n",
       "      <td>9</td>\n",
       "      <td>Buena Vista</td>\n",
       "      <td>$1,405.40</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jurassic World: Fallen Kingdom</th>\n",
       "      <td>13</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$1,309.50</td>\n",
       "      <td>2018</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Break-Up</th>\n",
       "      <td>763</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$205.00</td>\n",
       "      <td>2006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Everest</th>\n",
       "      <td>766</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$203.40</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Patch Adams</th>\n",
       "      <td>772</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$202.30</td>\n",
       "      <td>1998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kindergarten Cop</th>\n",
       "      <td>775</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$202.00</td>\n",
       "      <td>1990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Straight Outta Compton</th>\n",
       "      <td>776</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$201.60</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>140 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                Rank       Studio       Gross  Year\n",
       "Title                                                              \n",
       "Star Wars: The Force Awakens       4  Buena Vista  $2,068.20   2015\n",
       "Jurassic World                     6    Universal  $1,671.70   2015\n",
       "Furious 7                          8    Universal  $1,516.00   2015\n",
       "Avengers: Age of Ultron            9  Buena Vista  $1,405.40   2015\n",
       "Jurassic World: Fallen Kingdom    13    Universal  $1,309.50   2018\n",
       "...                              ...          ...         ...   ...\n",
       "The Break-Up                     763    Universal    $205.00   2006\n",
       "Everest                          766    Universal    $203.40   2015\n",
       "Patch Adams                      772    Universal    $202.30   1998\n",
       "Kindergarten Cop                 775    Universal    $202.00   1990\n",
       "Straight Outta Compton           776    Universal    $201.60   2015\n",
       "\n",
       "[140 rows x 4 columns]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "released_by_universal = movies[\"Studio\"] == \"Universal\"\n",
    "released_in_2015 = movies[\"Year\"] == 2015\n",
    "movies[released_by_universal | released_in_2015]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Rank</th>\n",
       "      <th>Studio</th>\n",
       "      <th>Gross</th>\n",
       "      <th>Year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Title</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>The Exorcist</th>\n",
       "      <td>252</td>\n",
       "      <td>Warner Brothers</td>\n",
       "      <td>$441.30</td>\n",
       "      <td>1973</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Gone with the Wind</th>\n",
       "      <td>288</td>\n",
       "      <td>MGM</td>\n",
       "      <td>$402.40</td>\n",
       "      <td>1939</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Bambi</th>\n",
       "      <td>540</td>\n",
       "      <td>RKO</td>\n",
       "      <td>$267.40</td>\n",
       "      <td>1942</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Godfather</th>\n",
       "      <td>604</td>\n",
       "      <td>Paramount</td>\n",
       "      <td>$245.10</td>\n",
       "      <td>1972</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101 Dalmatians</th>\n",
       "      <td>708</td>\n",
       "      <td>Buena Vista</td>\n",
       "      <td>$215.90</td>\n",
       "      <td>1961</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Jungle Book</th>\n",
       "      <td>755</td>\n",
       "      <td>Buena Vista</td>\n",
       "      <td>$205.80</td>\n",
       "      <td>1967</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    Rank           Studio     Gross  Year\n",
       "Title                                                    \n",
       "The Exorcist         252  Warner Brothers  $441.30   1973\n",
       "Gone with the Wind   288              MGM  $402.40   1939\n",
       "Bambi                540              RKO  $267.40   1942\n",
       "The Godfather        604        Paramount  $245.10   1972\n",
       "101 Dalmatians       708      Buena Vista  $215.90   1961\n",
       "The Jungle Book      755      Buena Vista  $205.80   1967"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "before_1975 = movies[\"Year\"] < 1975\n",
    "movies[before_1975]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Rank</th>\n",
       "      <th>Studio</th>\n",
       "      <th>Gross</th>\n",
       "      <th>Year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Title</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Return of the Jedi</th>\n",
       "      <td>222</td>\n",
       "      <td>Fox</td>\n",
       "      <td>$475.10</td>\n",
       "      <td>1983</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Back to the Future</th>\n",
       "      <td>311</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$381.10</td>\n",
       "      <td>1985</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Top Gun</th>\n",
       "      <td>357</td>\n",
       "      <td>Paramount</td>\n",
       "      <td>$356.80</td>\n",
       "      <td>1986</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Indiana Jones and the Temple of Doom</th>\n",
       "      <td>403</td>\n",
       "      <td>Paramount</td>\n",
       "      <td>$333.10</td>\n",
       "      <td>1984</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Crocodile Dundee</th>\n",
       "      <td>413</td>\n",
       "      <td>Paramount</td>\n",
       "      <td>$328.20</td>\n",
       "      <td>1986</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Beverly Hills Cop</th>\n",
       "      <td>432</td>\n",
       "      <td>Paramount</td>\n",
       "      <td>$316.40</td>\n",
       "      <td>1984</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Rocky IV</th>\n",
       "      <td>467</td>\n",
       "      <td>MGM</td>\n",
       "      <td>$300.50</td>\n",
       "      <td>1985</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Rambo: First Blood Part II</th>\n",
       "      <td>469</td>\n",
       "      <td>TriStar</td>\n",
       "      <td>$300.40</td>\n",
       "      <td>1985</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ghostbusters</th>\n",
       "      <td>485</td>\n",
       "      <td>Columbia</td>\n",
       "      <td>$295.20</td>\n",
       "      <td>1984</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Out of Africa</th>\n",
       "      <td>662</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$227.50</td>\n",
       "      <td>1985</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                      Rank     Studio     Gross  Year\n",
       "Title                                                                \n",
       "Return of the Jedi                     222        Fox  $475.10   1983\n",
       "Back to the Future                     311  Universal  $381.10   1985\n",
       "Top Gun                                357  Paramount  $356.80   1986\n",
       "Indiana Jones and the Temple of Doom   403  Paramount  $333.10   1984\n",
       "Crocodile Dundee                       413  Paramount  $328.20   1986\n",
       "Beverly Hills Cop                      432  Paramount  $316.40   1984\n",
       "Rocky IV                               467        MGM  $300.50   1985\n",
       "Rambo: First Blood Part II             469    TriStar  $300.40   1985\n",
       "Ghostbusters                           485   Columbia  $295.20   1984\n",
       "Out of Africa                          662  Universal  $227.50   1985"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mid_80s = movies[\"Year\"].between(1983, 1986)\n",
    "movies[mid_80s]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Rank</th>\n",
       "      <th>Studio</th>\n",
       "      <th>Gross</th>\n",
       "      <th>Year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Title</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Transformers: Dark of the Moon</th>\n",
       "      <td>23</td>\n",
       "      <td>Paramount</td>\n",
       "      <td>$1,123.80</td>\n",
       "      <td>2011</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Dark Knight Rises</th>\n",
       "      <td>27</td>\n",
       "      <td>Warner Brothers</td>\n",
       "      <td>$1,084.90</td>\n",
       "      <td>2012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Dark Knight</th>\n",
       "      <td>39</td>\n",
       "      <td>Warner Brothers</td>\n",
       "      <td>$1,004.90</td>\n",
       "      <td>2008</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Thor: The Dark World</th>\n",
       "      <td>132</td>\n",
       "      <td>Buena Vista</td>\n",
       "      <td>$644.60</td>\n",
       "      <td>2013</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Star Trek Into Darkness</th>\n",
       "      <td>232</td>\n",
       "      <td>Paramount</td>\n",
       "      <td>$467.40</td>\n",
       "      <td>2013</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Fifty Shades Darker</th>\n",
       "      <td>309</td>\n",
       "      <td>Universal</td>\n",
       "      <td>$381.50</td>\n",
       "      <td>2017</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dark Shadows</th>\n",
       "      <td>600</td>\n",
       "      <td>Warner Brothers</td>\n",
       "      <td>$245.50</td>\n",
       "      <td>2012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dark Phoenix</th>\n",
       "      <td>603</td>\n",
       "      <td>Fox</td>\n",
       "      <td>$245.10</td>\n",
       "      <td>2019</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                Rank           Studio       Gross  Year\n",
       "Title                                                                  \n",
       "Transformers: Dark of the Moon    23        Paramount  $1,123.80   2011\n",
       "The Dark Knight Rises             27  Warner Brothers  $1,084.90   2012\n",
       "The Dark Knight                   39  Warner Brothers  $1,004.90   2008\n",
       "Thor: The Dark World             132      Buena Vista    $644.60   2013\n",
       "Star Trek Into Darkness          232        Paramount    $467.40   2013\n",
       "Fifty Shades Darker              309        Universal    $381.50   2017\n",
       "Dark Shadows                     600  Warner Brothers    $245.50   2012\n",
       "Dark Phoenix                     603              Fox    $245.10   2019"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "has_dark_in_title = movies.index.str.lower().str.contains(\"dark\")\n",
    "movies[has_dark_in_title]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.3.5 Grouping Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Title\n",
       "Avengers: Endgame               2796.30 \n",
       "Avatar                          2789.70 \n",
       "Titanic                         2187.50 \n",
       "Star Wars: The Force Awakens    2068.20 \n",
       "Avengers: Infinity War          2048.40 \n",
       "                                  ...   \n",
       "Yogi Bear                        201.60 \n",
       "Garfield: The Movie              200.80 \n",
       "Cats & Dogs                      200.70 \n",
       "The Hunt for Red October         200.50 \n",
       "Valkyrie                         200.30 \n",
       "Name: Gross, Length: 782, dtype: object"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies[\"Gross\"].str.replace(\n",
    "    \"$\", \"\", regex = False\n",
    ").str.replace(\",\", \"\", regex = False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Title\n",
       "Avengers: Endgame               2796.3\n",
       "Avatar                          2789.7\n",
       "Titanic                         2187.5\n",
       "Star Wars: The Force Awakens    2068.2\n",
       "Avengers: Infinity War          2048.4\n",
       "                                 ...  \n",
       "Yogi Bear                        201.6\n",
       "Garfield: The Movie              200.8\n",
       "Cats & Dogs                      200.7\n",
       "The Hunt for Red October         200.5\n",
       "Valkyrie                         200.3\n",
       "Name: Gross, Length: 782, dtype: float64"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(\n",
    "    movies[\"Gross\"]\n",
    "    .str.replace(\"$\", \"\", regex = False)\n",
    "    .str.replace(\",\", \"\", regex = False)\n",
    "    .astype(float)\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "movies[\"Gross\"] = (\n",
    "    movies[\"Gross\"]\n",
    "    .str.replace(\"$\", \"\", regex = False)\n",
    "    .str.replace(\",\", \"\", regex = False)\n",
    "    .astype(float)\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "439.0308184143222"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies[\"Gross\"].mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "studios = movies.groupby(\"Studio\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Studio\n",
       "Artisan                     1\n",
       "Buena Vista               125\n",
       "CL                          1\n",
       "China Film Corporation      1\n",
       "Columbia                    5\n",
       "Name: Gross, dtype: int64"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "studios[\"Gross\"].count().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Studio\n",
       "Warner Brothers    132\n",
       "Buena Vista        125\n",
       "Fox                117\n",
       "Universal          109\n",
       "Sony                86\n",
       "Name: Gross, dtype: int64"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "studios[\"Gross\"].count().sort_values(ascending = False).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Studio\n",
       "Artisan                     248.6\n",
       "Buena Vista               73585.0\n",
       "CL                          228.1\n",
       "China Film Corporation      699.8\n",
       "Columbia                   1276.6\n",
       "Name: Gross, dtype: float64"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "studios[\"Gross\"].sum().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Studio\n",
       "Buena Vista        73585.0\n",
       "Warner Brothers    58643.8\n",
       "Fox                50420.8\n",
       "Universal          44302.3\n",
       "Sony               32822.5\n",
       "Name: Gross, dtype: float64"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "studios[\"Gross\"].sum().sort_values(ascending = False).head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.4 Summary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
